package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    /**
     reportData:{
         reportDate:null,//日期
         todayNewMember :0,//今日新增会员数
         totalMember :0,//总会员数
         thisWeekNewMember :0,//本周新会员
         thisMonthNewMember :0,//本月新会员
        todayOrderNumber :0,//今日预约数量
        todayVisitsNumber :0,//今日到诊数量
         thisWeekOrderNumber :0,//本周预约数量
         thisWeekVisitsNumber :0,//本周到诊数量
         thisMonthOrderNumber :0,//本月预约数量
         thisMonthVisitsNumber :0,//本月到诊数量

         hotSetmeal :[//热门套餐
             {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
             {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
        ]
     }
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //今日日期  reportDate
        Date date = new Date();
        String reportDate = DateUtils.parseDate2String(date);
        //本周第一天
        String fristDayOfWeek = DateUtils.parseDate2String(DateUtils.getFirstDayOfWeek(date));
        //本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());


        //今日新增会员数  todayNewMember
        Integer todayNewMember = memberDao.getTodayNewMember(reportDate);

        //总会员数  totalMember
        Integer totalMember = memberDao.getTotalMember();

        //thisWeekNewMember :0,//本周新会员
        Integer thisWeekNewMember = memberDao.getThisWeekNewMember(fristDayOfWeek);

        //本月新会员  thisMonthNewMember
        Integer thisMonthNewMember = memberDao.getThisMonthNewMember(firstDay4ThisMonth);

        //todayOrderNumber :0,//今日预约数量
        Integer todayOrderNumber = orderDao.getTodayOrderNumber(reportDate);

        //todayVisitsNumber :0,//今日到诊数量
        Integer todayVisitsNumber = orderDao.getTodayVisitsNumber(reportDate);

        //thisWeekOrderNumber :0,//本周预约数量
        Integer thisWeekOrderNumber = orderDao.getThisWeekOrderNumber(fristDayOfWeek);

        //thisWeekVisitsNumber :0,//本周到诊数量
        Integer thisWeekVisitsNumber = orderDao.getThisWeekVisitsNumber(fristDayOfWeek);

        //thisMonthOrderNumber :0,//本月预约数量
        Integer thisMonthOrderNumber = orderDao.getThisMonthOrderNumber(firstDay4ThisMonth);

        //thisMonthVisitsNumber :0,//本月到诊数量
        Integer thisMonthVisitsNumber = orderDao.getThisMonthVisitsNumber(firstDay4ThisMonth);

        //hotSetmeal :[//热门套餐
        List<Map<String,Object>> hotSetmeal = orderDao.getHotSetmeal();

        Map<String,Object> data = new HashMap<>();
        data.put("reportDate",reportDate);
        //Member相关
        data.put("todayNewMember",todayNewMember);
        data.put("totalMember",totalMember);
        data.put("thisWeekNewMember",thisWeekNewMember);
        data.put("thisMonthNewMember",thisMonthNewMember);
        //Order相关
        data.put("todayOrderNumber",todayOrderNumber);
        data.put("todayVisitsNumber",todayVisitsNumber);
        data.put("thisWeekOrderNumber",thisWeekOrderNumber);
        data.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        data.put("thisMonthOrderNumber",thisMonthOrderNumber);
        data.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        //hotSetmeal :[//热门套餐
        data.put("hotSetmeal",hotSetmeal);
        return data;
    }
}
